<template>
	<view>
		<view class="container" v-show="show">
			<view v-show="!showEmpty" class="message">访问时请凭此二维码到前台登记</view>
			<ikun-qrcode v-show="!showEmpty" class="qr-body" width="500" height="500" unit="rpx" :data="pageUrl" />
			<view class="user" v-show="!showEmpty">
				<view class="user-info">
					访客姓名：{{appointName}}
				</view>
				<view class="user-info">
					来访人数：{{num}}
				</view>
				<view class="user-info">
					到访日期：{{appointTime}}
				</view>
			</view>

			<u-empty v-show="showEmpty" class="qr-body" icon="/static/empty.png" iconColor="#ccc" mode="data"
				text="无预约数据">
			</u-empty>
		</view>
	</view>
</template>

<script>
	import config from '@/utils/config.js'
	import {
		getOpenid
	} from "@/common/permission.js"
	export default {
		data() {
			return {
				showEmpty: false,
				id: '',
				openid: '',
				show: false,
				appointName: '',
				appointTime: '',
				num: 1,
				count: 1,
			}
		},
		async onLoad(e) {
			console.log("=================", e.id)
			const id = e.id
			if (id) {
				this.queryDataById(id)
				// this.id = id
			} else {
				this.openid = await getOpenid()
				this.loadData()
			}
		},
		computed: {
			pageUrl() {
				return config.QRCodePageUrl + '?id=' + this.id
			}
		},
		methods: {
			queryDataById(id) {
				this.$request({
					url: '/appoint/detail?id=' + id
				}).then(res => {
					if (res.data) {
						this.id = res.data.id
						this.appointName = res.data.appointName
						this.appointTime = res.data.appointTime
						this.num = res.data.num
						this.showEmpty = false
					} else {
						this.showEmpty = true
					}
					if (res.data.list) {
						this.count = res.data.list.length + 1;
					}
					this.show = true
				}).catch((e) => {
					console.log("请求异常==============", e)
					this.showEmpty = true
				}).finally(() => {
					uni.hideLoading()
					this.show = true
				})
			},
			loadData() {
				uni.showLoading()
				this.$request({
						url: '/appoint/getAppointInfo?openid=' + this.openid
					}).then(res => {
						console.log("我的二维码数据：", res.data)
						console.log(this.id, "========111")
						if (res.data) {
							this.id = res.data.id
							if (this.id) {
								this.showEmpty = false
								this.appointName = res.data.appointName
								this.appointTime = res.data.appointTime
								this.num = res.data.num
							} else {
								this.showEmpty = true
							}
						} else {
							this.showEmpty = true
						}
						this.show = true
						console.log(this.id, "========2222", this.showEmpty)

					}).catch(this.showEmpty = true)
					.finally(() => {
						uni.hideLoading()
						this.show = true

					})
			},

		}
	}
</script>

<style lang="scss" scoped>
	.input-placeholder {
		font-size: 12px;
	}

	.message {
		margin-bottom: -100px;
		margin-top: 80px;
		font-size: 38rpx;
	}

	.container {
		display: flex;
		flex-direction: column;
		// justify-content: center;
		align-items: center;
		background: #f3f3f3;
		height: 100vh;

		.qr-body {
			margin-top: 300rpx !important;
		}

		.user {
			display: flex;
			flex-direction: column;

		}

		.user-info {
			margin-top: 20rpx;
		}

	}
</style>